home *** CD-ROM | disk | FTP | other *** search
- class Vehicle
- {
- var index;
- var position;
- var aDropZones;
- var bmpCanvas;
- var bmpVehicle;
- var width;
- var height;
- var bDestroyed;
- var mode;
- var frameExp;
- var bTaken;
- var vel;
- var screenPos;
- var bOnScreen;
- var sType = "vehicle";
- static var maxDist = 10;
- var weightFactor = 3;
- var angle = 0;
- function Vehicle(posNew, id, aDropZonesNew, indexNew)
- {
- this.index = indexNew;
- this.position = posNew.clone();
- this.aDropZones = aDropZonesNew;
- this.bmpCanvas = Game.bmpShots;
- this.bmpVehicle = flash.display.BitmapData.loadBitmap("vehicle " + id);
- this.width = this.bmpVehicle.width;
- this.height = this.bmpVehicle.height;
- this.bDestroyed = false;
- this.mode = 0;
- this.frameExp = 0;
- this.bTaken = false;
- this.vel = new flash.geom.Point(0,0);
- }
- function step(refRope)
- {
- if(this.mode == 0)
- {
- var _loc6_ = refRope.endPos.x - this.position.x;
- var _loc5_ = refRope.endPos.y - this.position.y;
- if(Math.abs(_loc5_) < 10 && Math.abs(_loc6_) < 10 && !refRope.bHasCargo)
- {
- this.mode = 1;
- refRope.refCargo = this;
- refRope.bHasCargo = true;
- Game.getInstance().mcAlert.gotoAndPlay("show2");
- }
- }
- else if(this.mode == 1)
- {
- this.position.x = refRope.endPos.x;
- this.position.y = refRope.endPos.y;
- if(this.checkPlatform())
- {
- Game.getInstance().saveVehicleInd(this.index);
- Game.getInstance().checkIfCompleted();
- this.mode = null;
- refRope.refCargo = null;
- refRope.bHasCargo = false;
- }
- else
- {
- var _loc7_ = this.checkCollision();
- if((_loc7_ || this.position.y < 41) && this.bTaken)
- {
- this.die();
- }
- else if(!this.bTaken && this.position.y > 44)
- {
- this.bTaken = true;
- }
- }
- }
- else if(this.mode == 2)
- {
- this.vel.y -= 0.5;
- this.vel.x *= 0.98;
- this.vel.y *= 0.98;
- this.position.x += this.vel.x;
- this.position.y += this.vel.y;
- var _loc3_ = 0;
- while(_loc3_ < this.aDropZones.length)
- {
- var _loc2_ = this.aDropZones[_loc3_];
- if(this.position.x - this.width / 2 > _loc2_.plaPos.x && this.position.x + this.width / 2 < _loc2_.plaPos.x + _loc2_.plaWidth && this.position.y - _loc2_.plaPos.y < this.height / 2 + 2)
- {
- this.position.y = _loc2_.plaPos.y + this.height / 2;
- if(Math.abs(this.vel.y) < 0.5)
- {
- Game.getInstance().saveVehicleInd(this.index);
- Game.getInstance().checkIfCompleted();
- this.mode = null;
- }
- this.vel.x = 0;
- this.vel.y = Math.abs(this.vel.y) * 0.7;
- }
- else if(this.checkCollision() || this.position.y < 40)
- {
- this.die();
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- }
- function draw(leftEdge)
- {
- var _loc2_ = this.position.x - leftEdge - this.width / 2;
- var _loc5_ = this.position.y + this.height / 2;
- this.screenPos = new flash.geom.Point(_loc2_,_loc5_);
- if(!this.bDestroyed)
- {
- if(_loc2_ > - this.width && _loc2_ < Game.screenW + this.width)
- {
- this.bOnScreen = true;
- if(this.mode == 0)
- {
- var _loc3_ = Math.sin(this.angle) + 1;
- this.angle += 0.6;
- var _loc6_ = new flash.display.BitmapData(this.width + 10,this.height + 10,true,0);
- var _loc9_ = 16777215;
- var _loc15_ = 0.4 + 0.4 * _loc3_;
- var _loc12_ = 3 + 4 * _loc3_;
- var _loc11_ = 3 + 4 * _loc3_;
- var _loc13_ = 4 + 4 * _loc3_;
- var _loc7_ = 1;
- var _loc10_ = false;
- var _loc14_ = false;
- var _loc8_ = new flash.filters.GlowFilter(_loc9_,_loc15_,_loc12_,_loc11_,_loc13_,_loc7_,_loc10_,_loc14_);
- _loc6_.applyFilter(this.bmpVehicle,this.bmpVehicle.rectangle,new flash.geom.Point(5,5),_loc8_);
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(this.screenPos.x + 5,Game.screenH - this.screenPos.y - 5);
- this.bmpCanvas.draw(_loc6_,_loc4_,null,null,null,true);
- }
- else
- {
- this.bmpCanvas.copyPixels(this.bmpVehicle,this.bmpVehicle.rectangle,new flash.geom.Point(_loc2_,Game.screenH - _loc5_),null,null,true);
- }
- }
- }
- else
- {
- this.drawExplosion(new flash.geom.Point(this.position.x - leftEdge,this.position.y),true);
- }
- if(this.mode == null && (_loc2_ < - this.width || _loc2_ > Game.screenW + this.width))
- {
- Game.getInstance().removeVehicle(this);
- }
- }
- function die(Void)
- {
- this.mode = null;
- this.bDestroyed = true;
- Sounds.playSound("bazooka");
- }
- function drawExplosion(pos, bRemove)
- {
- var _loc3_ = _root.attachMovie("explosion2","mcExp",_root.getNextHighestDepth());
- _loc3_.gotoAndStop(this.frameExp + 1);
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(pos.x,Game.screenH - pos.y);
- this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
- _loc3_.removeMovieClip();
- this.frameExp = this.frameExp + 1;
- if(this.frameExp == 27)
- {
- if(bRemove)
- {
- this.onEndDeadAnim();
- }
- }
- }
- function onEndDeadAnim(Void)
- {
- Game.getInstance().onLooseLife();
- }
- function checkCollision(Void)
- {
- var _loc3_ = - this.screenPos.x;
- var _loc2_ = - (Game.screenH - this.screenPos.y);
- return Game.bmpDead.hitTest(new flash.geom.Point(_loc3_,_loc2_),250,this.bmpVehicle,new flash.geom.Point(0,0),250);
- }
- function checkPlatform(Void)
- {
- var _loc3_ = 0;
- while(_loc3_ < this.aDropZones.length)
- {
- var _loc2_ = this.aDropZones[_loc3_];
- if(this.position.x - this.width / 2 > _loc2_.plaPos.x && this.position.x + this.width / 2 < _loc2_.plaPos.x + _loc2_.plaWidth && this.position.y - _loc2_.plaPos.y < this.height / 2 + 2)
- {
- this.position.y = _loc2_.plaPos.y + this.height / 2;
- return true;
- }
- _loc3_ = _loc3_ + 1;
- }
- return false;
- }
- }
-